<?php
$dir = dirname(__FILE__);
require_once "$dir/DocTest/Source.php";
require_once "$dir/DocTest/Parser.php";
require_once "$dir/DocTest/Runner.php";

/**
 * doctest 클래스
 *
 * 테스트는 이런 식으로 합니다. (자기 자신의 테스트는 통과해야겠죠?)
 * php> DocTest::testFile('DocTest/Source.php');
 * php> DocTest::testFile('DocTest/Parser.php');
 * php> DocTest::testFile('DocTest/Runner.php');
 */
class DocTest {
	function testFile($path) {
		$source = new DocTestSource(file_get_contents($path));
		$comments = $source->getDocComments();
		$parser = new DocTestParser;
		foreach ($comments as $comment) {
			$examples = $parser->parse($comment);
			$runner = new DocTestRunner($examples);
			$result = $runner->run();
			if (!$result->passed()) {
				echo "File \"$path\", line {$result->example->lineNumber}\n";
				echo "Failed example:\n\t{$result->example->source}\n";
				echo "Expected:\n\t{$result->example->expect}\n";
				echo "Got:\n\t";
				var_export($result->result);
			}
		}
	}
}
